//
//  YTSysSetBaseVC.m
//  YUNT
//
//  Created by 梁炜东 on 2017/11/20.
//  Copyright © 2017年 梁炜东. All rights reserved.
//

#import "YTSysSetBaseVC.h"

@interface YTSysSetBaseVC ()
@property(nonatomic, strong)UIView *line;
@end

@implementation YTSysSetBaseVC
-(void)backAction:(UIButton *)sender
{
//    [self.navigationController dismissViewControllerAnimated:YES completion:^{
//    }];
    [self.navigationController popViewControllerAnimated:YES];
}
-(instancetype)initWithType:(YTSysSetType)setType
{
    self = [super init];
    if (self)
    {
        _setType = setType;
        if (_setType == YTSysSetCameraType)
        {
            _dataSources = [NSMutableArray arrayWithArray:@[@[Language(@"视频格式"), Language(@"视频制式")], @[Language(@"照片比例"), Language(@"延时摄影格式")], @[Language(@"抗闪烁"), Language(@"文件序号模式"), Language(@"恢复相机出厂设置")]]];
            _sectionData = [NSMutableArray arrayWithArray:@[Language(@"视频"), Language(@"照片"), Language(@"通用")]];
        }else if (_setType == YTSysSetYunTaiType)
        {
            _dataSources = [NSMutableArray arrayWithArray:@[@[@"", Language(@"高级")], @[Language(@"方向"), Language(@"俯仰")], @[Language(@"方向"), Language(@"俯仰")], @[Language(@"水平校准"), Language(@"自动校准")]]];
            _sectionData = [NSMutableArray arrayWithArray:@[Language(@"快速配置"), Language(@"平滑跟踪设置"), Language(@"控制杆"), Language(@"校准")]];
        }else if (_setType == YTSysSetUniversalType)
        {
            _dataSources = [NSMutableArray arrayWithArray:@[@[@"删除全部视频缓存", Language(@"视频缓存"), Language(@"自动清理缓存(当占用空间大于2GB)")], @[Language(@"格式化SD卡"), Language(@"关于")]]];
            _sectionData = [NSMutableArray arrayWithArray:@[Language(@"缓存"), Language(@"其他")]];
        }
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    self.view.backgroundColor = YTColor(55, 55, 55);
    [self p_addSubViews];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _sectionData.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *arr =self.dataSources[section];
    return arr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 60;
}
//设置head foot的背景色 必须通过下面这个代理
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    view.tintColor = [UIColor clearColor];
}
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
    if([UIApplication sharedApplication].statusBarOrientation ==UIInterfaceOrientationPortrait||[UIApplication sharedApplication].statusBarOrientation ==UIInterfaceOrientationPortraitUpsideDown)
    {//竖屏
        [_backBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).offset(20);
            make.leading.equalTo(self.view);
            make.height.mas_equalTo(44);
            make.width.mas_equalTo(70);
        }];
    }else
    {
        [_backBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.leading.equalTo(self.view);
            make.height.mas_equalTo(44);
            make.width.mas_equalTo(70);
        }];
    }
    [_rightBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerY.top.bottom.equalTo(_backBtn);
        make.width.mas_equalTo(70);
    }];
    [_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(_backBtn);
        make.leading.equalTo(_backBtn.mas_trailing);
        make.trailing.equalTo(_rightBtn.mas_leading);
    }];
    [_line mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.view);
        make.height.mas_equalTo(1);
        make.top.equalTo(_backBtn.mas_bottom).offset(6);
    }];
    [_myTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.equalTo(self.view);
        make.top.equalTo(_line.mas_bottom);
    }];
}
-(void)p_addSubViews
{
    [self.view addSubview:self.backBtn];
    [self.view addSubview:self.titleLabel];
    [self.view addSubview:self.rightBtn];
    [self.view addSubview:self.line];
    [self.view addSubview:self.myTableView];
}
-(UIButton *)backBtn
{
    if (!_backBtn)
    {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        _backBtn.titlePosition = XYButtonTitlePositionNomal;
        _backBtn.userInteractionEnabled = YES;
        _backBtn.backgroundColor = [UIColor clearColor];
        [_backBtn setImage:IMAGE(@"53") forState:UIControlStateNormal];
        [_backBtn setTitleColor:YTColor(92, 204, 225) forState:UIControlStateNormal];
        _backBtn.titleLabel.font = [UIFont systemFontOfSize:17];
//        [_backBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -80)];
//        [_backBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 21, 0, 0)];
        [_backBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}
-(UILabel *)titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}
-(XYButton *)rightBtn
{
    if (!_rightBtn)
    {
        _rightBtn = [XYButton buttonWithType:UIButtonTypeCustom];
        _rightBtn.titlePosition = XYButtonTitlePositionNomal;
        _rightBtn.userInteractionEnabled = NO;
        _rightBtn.backgroundColor = [UIColor clearColor];
        [_rightBtn setTitle:Language(@"完成") forState:UIControlStateNormal];
        [_rightBtn setTitleColor:YTColor(92, 204, 225) forState:UIControlStateNormal];
    }
    return _rightBtn;
}
-(UIView *)line
{
    if (!_line)
    {
        _line = [[UIView alloc] init];
        _line.backgroundColor = YTColorAlpha(180, 180, 180, 0.3);
    }
    return _line;
}
-(UITableView *)myTableView
{
    if (!_myTableView)
    {
        _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        _myTableView.backgroundColor = [UIColor clearColor];
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _myTableView;
}

@end
